package com.coderman.infosys.auth.app.facadeimpl.config;

import com.coderman.infosys.auth.api.dto.config.DataColumnQueryObj;
import com.coderman.infosys.auth.domain.bo.config.DataColumnBO;
import com.coderman.infosys.auth.domain.enums.errors.DataColumnErrorEnum;
import com.coderman.infosys.auth.app.convert.DataColumnConvert;
import com.coderman.infosys.auth.domain.gataway.DataColumnConfigGataway;
import com.coderman.infosys.plat.auth.common.dto.PageDTO;
import com.coderman.infosys.plat.auth.common.dto.ResultDataDto;
import com.coderman.infosys.plat.auth.common.page.PageBO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import com.coderman.infosys.auth.api.facade.config.DataColumnFacade;
import com.coderman.infosys.auth.api.dto.config.DataColumnDTO;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import javax.xml.crypto.Data;


/**
 * @Description:数据配置接口实现类
 * @Author：
 * @CreateTime：2022-01-02 15:27:39
 * @version v1.0
 */
@Service
public class DataColumnFacadeImpl   implements DataColumnFacade{


    @Autowired
    private DataColumnConfigGataway dataColumnConfigGataway;


    @Override
    public ResultDataDto<List<DataColumnDTO>> getListByBusDataBase(String busDataBase){
        List<DataColumnBO> dataColumnBOList = dataColumnConfigGataway.getByBusDatabase(busDataBase);
        return ResultDataDto.success(DataColumnConvert.INSTANCE.dataColumnBOs2dtoList(dataColumnBOList));
    }

    @Override
    public ResultDataDto<PageDTO<DataColumnDTO, DataColumnQueryObj>> getPageList(PageDTO<DataColumnDTO, DataColumnQueryObj> pageDTO){
        PageBO pageBO = pageDTO.convertToBO();
        List<DataColumnBO> dataColumnBOList = dataColumnConfigGataway.getPageList(pageBO);
        List<DataColumnDTO> dataColumnDTOList = DataColumnConvert.INSTANCE.dataColumnBOs2dtoList(dataColumnBOList);
        return ResultDataDto.success(pageDTO.initData(dataColumnDTOList,pageBO.getTotalRows()));

    }

    @Override
    public ResultDataDto<Boolean> importDataColumnList(List<DataColumnDTO> dataColumnDTOList){
        boolean success = dataColumnConfigGataway.saveBatchDataColumn(DataColumnConvert.INSTANCE.dataColumnDTOs2boList(dataColumnDTOList));
        if(success){
            return ResultDataDto.success(success);
        }
        return ResultDataDto.fail(DataColumnErrorEnum.BATCH_INSERT_ERROR);
    }

    @Override
    public ResultDataDto<Boolean> insert(DataColumnDTO dataColumnDTO) {
        DataColumnBO dataColumnBO = DataColumnConvert.INSTANCE.dto2bo(dataColumnDTO);
        dataColumnConfigGataway.saveDataColumn(dataColumnBO);
        return ResultDataDto.success(true);
    }

    @Override
    public ResultDataDto<Boolean> update(DataColumnDTO dataColumnDTO) {
        DataColumnBO dataColumnBO = DataColumnConvert.INSTANCE.dto2bo(dataColumnDTO);
        dataColumnConfigGataway.updateDataColumn(dataColumnBO);
        return ResultDataDto.success(true);
    }

}